﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
using Albon.Model;

namespace DAL
{
    public class RoleDAL
    {
        //RoleInfo
        /// <summary>
        /// 添加或修改role,当ID为0时添加，ID不为0时修改相应role信息,添加成功则返回true 
        /// </summary>
        public bool alterRole(RoleInfo role)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4),
					new SqlParameter("@roleName", SqlDbType.VarChar,50),
					new SqlParameter("@startPage", SqlDbType.VarChar,50),
					new SqlParameter("@remark", SqlDbType.Text),
					new SqlParameter("@menuList", SqlDbType.Text),
					new SqlParameter("@active", SqlDbType.Bit,1)};
            parameters[0].Value = role.ID;
            parameters[1].Value = role.roleName;
            parameters[2].Value = role.startPage;
            parameters[3].Value = role.remark;
            parameters[4].Value = role.menuList;
            parameters[5].Value = role.active;
            return SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_rolealter", parameters)==1;
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int delRole(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] { 
                new SqlParameter("@id",id),
                new SqlParameter("@ret",SqlDbType.Int)
            };
            parameters[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_roledel", parameters);
            return (int)parameters[1].Value;
        }
        //根据查询条件获取信息
        public DataTable getRole(string limit)
        {
            string cmdstr = "select * from RoleInfo where "+limit;
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
        }
    }
}
